package com.jk.controller;

import com.jk.dto.TemCandidate;
import com.jk.dto.TemPosition;
import com.jk.pojo.PagedResponse;
import com.jk.pojo.ResponseResult;
import com.jk.service.TemCandidateServiceFeign;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author yzf
 * @version 1.0
 * @ClassName TemCandidateController
 * @program: office
 * @description: TODO
 * @date 2025/2/17 14:31
 */
@Api(tags = "候选人")
@RestController
@Slf4j
@RequestMapping("/cand")
public class TemCandidateController {
    @Autowired
    private TemCandidateServiceFeign temCandidateServiceFeign;

    @ApiOperation(value = "分页查询候选人",httpMethod = "POST",notes = "分页查询候选人")
    @RequestMapping("/findTemCandidateList")
    public ResponseResult<PagedResponse<TemCandidate>> findTemCandidateList(@RequestBody TemCandidate temCandidate, @RequestParam(value = "pageNum") Integer pageNum, @RequestParam(value = "pageSize") Integer pageSize){
        return new ResponseResult<>(200,"查询成功",temCandidateServiceFeign.findTemCandidateList(temCandidate,pageNum,pageSize));
    }
    @ApiOperation(value = "修改状态",httpMethod = "POST",notes = "修改状态")
    @RequestMapping("/updateTemCandidate")
    public ResponseResult updateTemCandidate(@RequestBody TemCandidate temCandidate){
        try {
            temCandidateServiceFeign.updateTemCandidate(temCandidate);
            return new ResponseResult(200,"修改成功");

        } catch (Exception e) {
            e.printStackTrace();
            return new ResponseResult(500,"修改失败");
        }
    }

    @ApiOperation(value = "添加候选人",httpMethod = "POST",notes = "添加候选人")
    @RequestMapping("/addTemCandidate")
    public ResponseResult addTemCandidate(@RequestBody TemCandidate temCandidate){
        try {
            temCandidateServiceFeign.addTemCandidate(temCandidate);
            return new ResponseResult(200,"添加成功");

        } catch (Exception e) {
            e.printStackTrace();
            return new ResponseResult(500,"添加失败");
        }
    }
    @ApiOperation(value = "回显",httpMethod = "GET",notes = "回显")
    @RequestMapping("/getTemCandidateById")
    public ResponseResult<TemCandidate> getTemCandidateById(@RequestParam(value = "id") Integer id){
        return new ResponseResult<>(200,"查询成功",temCandidateServiceFeign.getTemCandidateById(id));
    }


    @ApiOperation(value = "修改流程",httpMethod = "POST",notes = "修改状态")
    @RequestMapping("/updateStateById")
    public ResponseResult updateStateById(@RequestParam(value = "id")Integer id,@RequestParam (value = "process") String process){
        try {
            temCandidateServiceFeign.updateStateById(id,process);
            return new ResponseResult(200,"修改成功");

        } catch (Exception e) {
            e.printStackTrace();
            return new ResponseResult(500,"修改失败");
        }
    }

    /** 
     * @description: 查询escharts数据
            * @param: [temCandidate]
            * @return: com.jk.pojo.ResponseResult
            * @author yzf
            * @date: 2025/2/21 14:32
     */ 
    @ApiOperation(value = "echarts",httpMethod = "POST",notes = "echarts")
    @RequestMapping("/findEchartsProcessList")
    public ResponseResult findEchartsProcessList(@RequestBody TemCandidate temCandidate){
        List<TemCandidate> echartsProcessList = temCandidateServiceFeign.findEchartsProcessList(temCandidate);
        List<Map<String,Object>> list = new ArrayList<>();
        for (TemCandidate candidate : echartsProcessList) {
            Map<String,Object> li = new HashMap<>();
            li.put("name",candidate.getProcess());
            li.put("value",candidate.getRenshu());
            list.add(li);
        }
        return new ResponseResult<>(200,"查询成功",list);
    }

    @ApiOperation(value = "统计",httpMethod = "GET",notes = "统计")
    @RequestMapping("/findCount")
    private ResponseResult findCount(){
            return new ResponseResult<>(200,"查询成功",  temCandidateServiceFeign.findCount());
    }

    @ApiOperation(value = "招聘概览",httpMethod = "GET",notes = "招聘概览统计")
    @RequestMapping("/findEchartsList")
    public ResponseResult findEchartsList(){
        List<TemCandidate> candidatesList = temCandidateServiceFeign.findEchartsList();
        SimpleDateFormat sdf = new SimpleDateFormat("MM-dd");
        List<String> dateList = candidatesList.stream()
                .map(item -> sdf.format(item.getDatetime()))
                .collect(Collectors.toList());
        List<Integer> zongList = candidatesList.stream()
                .map(item -> item.getZong())
                .collect(Collectors.toList());
        List<Integer> erviewList = candidatesList.stream()
                .map(item -> item.getMianshizhong())
                .collect(Collectors.toList());
        List<Integer> onboardingList = candidatesList.stream()
                .map(item -> item.getDairuzhi())
                .collect(Collectors.toList());

        Map<String, Object> params = new HashMap<>();
        params.put("dateList", dateList);
        params.put("zongList", zongList);
        params.put("mianshizhongList", erviewList);
        params.put("onboardingList", onboardingList);
        return new ResponseResult(200, "查询成功", params);
    }


    @ApiOperation(value = "数据",httpMethod = "GET",notes = "数据")
    @RequestMapping("/findShuJvList")
    public ResponseResult findShuJvList(){
        return new ResponseResult(200,"查询成功",temCandidateServiceFeign.findShuJvList());
    }



}
